package com.ztz.mynewdemo.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.github.chrisbanes.photoview.PhotoView;
import com.ztz.mynewdemo.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class PhotoDynamicActivity extends AppCompatActivity {
    public static final String IMAGE_URL = "imageurl";
    @BindView(R.id.photo_dynamic)
    PhotoView photoDynamic;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_photo_dynamic);
        ButterKnife.bind(this);
        String imageUrl = getIntent().getStringExtra(IMAGE_URL);
        if (imageUrl != null && !"".equals(imageUrl)) {
            //区分gif图片与普通图片
            if (imageUrl.endsWith(".gif")) {
                Glide.with(PhotoDynamicActivity.this)
                        .load(imageUrl)
                        .asGif()
                        .error(R.mipmap.ic_error)
                        .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                        .dontAnimate()
                        .into(photoDynamic);
            } else {
                Glide.with(PhotoDynamicActivity.this)
                        .load(imageUrl)
                        .crossFade()
                        .error(R.mipmap.ic_error)
                        .diskCacheStrategy(DiskCacheStrategy.ALL)
                        .into(photoDynamic);
            }
        }
    }
}
